package JET;

import JET.physics.engine.JETContext;
import JET.physics.engine.SpringsTreeNode;
import JET.physics.engine.RSpringsTreeNode;
import JET.physics.engine.SpringBodiesTreeNode;
import JET.physics.engine.TorquesTreeNode;
import JET.physics.interfaces.SceneTreeNode;


public final class SceneItem implements SceneTreeNode {

    public String name;

    private final JETContext engine = new JETContext();

    public SceneItem() {}

    public JETContext getEngine() { return engine; }
    
    ////////////////////////////////////////////////////////////////////////////
    //              S C E N E   I T E M   T R E E   S T U F F                 //
    ////////////////////////////////////////////////////////////////////////////

    public final SceneItemPhysicElementsNode   physicElementsNode = new SceneItemPhysicElementsNode();

    public final SpringBodiesTreeNode springBodiesTreeNode = new SpringBodiesTreeNode(engine.springBodyList);
    public final SpringsTreeNode springsTreeNode = new SpringsTreeNode(engine.springList);
    public final RSpringsTreeNode rSpringsTreeNode = new RSpringsTreeNode(engine.rSpringList);
    public final TorquesTreeNode torquesTreeNode = new TorquesTreeNode(engine.torqueList);


    public final SceneItemScriptsNode          scriptsNode = new SceneItemScriptsNode();

    public SceneTreeNode getChild(int index) {
        switch(index)
        {
            case 0:
                return physicElementsNode;
            case 1:
                return scriptsNode;
        }

        return null;
    }
    public int getChildCount() {
        return 2;
    }
    public boolean isLeaf() {
        return false;
    }
    public int getIndexOfChild(Object child) {
        if (child instanceof SceneItemPhysicElementsNode)
            return 0;
        else if (child instanceof SceneItemScriptsNode)
            return 1;
        
        return -1;
    }
    public void resetNodeValue(Object o) {}

    protected class SceneItemPhysicElementsNode implements SceneTreeNode {

        public static final int NODE_INDEX_SPRING_BODIES = 0;
        public static final int NODE_INDEX_SPRINGS = 1;
        public static final int NODE_INDEX_RSPRINGS = 2;
        public static final int NODE_INDEX_TORQUES = 3;

        public SceneTreeNode getChild(int index) {
            switch(index) {
                case NODE_INDEX_SPRING_BODIES :
                    return springBodiesTreeNode;
                case NODE_INDEX_SPRINGS :
                    return springsTreeNode;
                case NODE_INDEX_RSPRINGS :
                    return rSpringsTreeNode;
                case NODE_INDEX_TORQUES :
                    return torquesTreeNode;
            }

            return null;
        }

        public int getChildCount() {
            return 4;
        }
        public boolean isLeaf() {
            return false;
        }
        public int getIndexOfChild(Object child) {
            if      (child instanceof SpringBodiesTreeNode) return NODE_INDEX_SPRING_BODIES;
            else if (child instanceof SpringsTreeNode) return NODE_INDEX_SPRINGS;
            else if (child instanceof RSpringsTreeNode) return NODE_INDEX_RSPRINGS;
            else if (child instanceof TorquesTreeNode) return NODE_INDEX_TORQUES;
            else return -1;
        }
        public void resetNodeValue(Object o) {}
        public String toString() {
            return "Physics";
        }
    }

    protected class SceneItemScriptsNode implements SceneTreeNode {

        public SceneTreeNode getChild(int index) {
            return null;
        }
        public int getChildCount() {
            return 0;
        }
        public boolean isLeaf() {
            return true;
        }
        public int getIndexOfChild(Object child) {
            return -1;
        }
        public void resetNodeValue(Object o) {}
        public String toString() {
            return "Scripts";
        }
    }
}